using System.Windows.Controls;
using System.Windows;
using System.Collections.Generic;
using SanmaoTools.Models;

namespace Tryit.Views
{
    public partial class ElementManagementView : Page
    {
        public ElementManagementView()
        {
            InitializeComponent();
        }

        private void PhysicalPropertiesDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataContext is ViewModels.ElementManagementViewModel viewModel)
            {
                var dataGrid = sender as DataGrid;
                if (dataGrid != null)
                {
                    viewModel.SelectedPhysicalProperties.Clear();
                    foreach (var item in dataGrid.SelectedItems)
                    {
                        if (item is PhysicalProperties property)
                        {
                            viewModel.SelectedPhysicalProperties.Add(property);
                        }
                    }
                }
            }
        }

        private void ElementsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataContext is ViewModels.ElementManagementViewModel viewModel)
            {
                var dataGrid = sender as DataGrid;
                if (dataGrid != null)
                {
                    viewModel.SelectedElements.Clear();
                    foreach (var item in dataGrid.SelectedItems)
                    {
                        if (item is Element element)
                        {
                            viewModel.SelectedElements.Add(element);
                        }
                    }
                }
            }
        }
    }
} 